﻿@page "{departmentId:int}"
@using Microsoft.AspNetCore.Mvc.RazorPages
@using ThreePage.Services
@using ThreePage.Models
@model EmployeeListModel
<div class="row">
    <div class="col-md-10 offset-md-2">
        <table class="table">
            <tr>
                <th>
                    First Name
                </th>
                <th>
                    Last Name
                </th>
                <th>
                    Gender
                </th>
                <th>
                    Is Fired
                </th>
                <th>
                    操作
                </th>
            </tr>
            @Html.DisplayFor(x => x.Employees)
        </table>
        <a asp-page="AddEmployee" asp-route-departmentId="@ViewData["DepartmentId"]">Add</a>
    </div>
</div>
@*<div class="row">
        <div class="col-md-4 offset-md-2">
            <a asp-action="Add" asp-route-departmentId="@ViewBag.DepartmentId">Add</a>
        </div>
    </div>*@

@functions{
    public class EmployeeListModel : PageModel
    {
        public readonly IEmployeeService _employeeService;

        public EmployeeListModel(IEmployeeService employeeService)
        {
            _employeeService = employeeService;
        }
        public IEnumerable<Three.Models.Employee> Employees { get; set; }

        public async Task OnGet(int departmentId)
        {
            Employees = await _employeeService.GetByDepartmentId(departmentId);
            ViewData["DepartmentId"] = departmentId;
        }
        public async Task<IActionResult> OnGetFireAsync(int employeeId, int departmentId)
        {
            await _employeeService.Fire(employeeId);

            return RedirectToPage("EmployeeList", new { departmentId });
        }
    }
}
